<?PHP

// This class is used as a wrapper for files
class folio_file {

    // Identifying information, uniquely ids any pieces of content, mapping back into Elgg.
    public $ident = -1;
    public $owner = -1;
    public $files_owner = -1;
    public $folder = -1;
    public $community = -1;
    public $title = '';
    public $originalname = '';
    public $description = '';
    public $location = '';
    public $access = '';
    public $size = -1;
    public $time_uploaded = -1;
    public $handler = '';

    // Constructor
    function __construct( $array = false ) {
        // Assume constructor is an array from the db.
        if ( !!$array ) {
            foreach ( $array as $n=>$v ) {
                $this->$n = $v;
            }
        }
    }

//////////////////
//              //
//  SQL Layer   //
//              //
//////////////////

    // Return the file for the passed ident.
    function SelectWhereIdent( $ident ) {
        global $CFG;

        $ident = intval( $ident );

        $query = "SELECT u.ident, u.* FROM {$CFG->prefix}files u " .
                    "WHERE u.ident = $ident";

        $records = recordset_to_array( get_recordset_sql( $query ));

        if( !$records ) {return false; }

        return new folio_file( $records[$ident] );
    }
}
?>
